home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: commitTrans.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:02 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "latch.h"
- #include "bf.h"
- #include "volume.h"
- #include "trans.h"
- #include "openlog.h"
- #include "logrecs.h"
- #include "logaction.h"
- #include "bitvec.h"
- #include "adminmsg.h"
- #include "trans_intfuncs.h"
- #include "trans_extfuncs.h"
- #include "lm_extfuncs.h"
- #include "log_extfuncs.h"
- #include "msg_funcs.h"
- #include "io_extfuncs.h"
- #include "io_globals.h"
- #include "trans_globals.h"
- #include "thread_globals.h"
- #include "admin_globals.h"
-
- /*
- * For write timing of log pages
- */
- extern FOUR StatTotalTime_usec;
- extern FOUR StatPagesWritten;
- extern FOUR StatWriteCalls;
- extern FOUR StatClientMsgs;
-
- void
- commitTrans (
-
- register TRANSREC *transRec
- )
- {
-
- DIRTYPAGELOGINFO *dirtyInfo = DirtyPageLogInfo;
- int numDirtyPages;
- LOGRECORDINFO recordInfo;
- FORCEMARK forceMark;
- LIST pendingBitmapList;
-
- TRPRINT(TR_TRANS, TR_LEVEL_2, ("tid:%x", GETTID(transRec)));
-
- if (PrintExtraStats && StatPagesWritten > 0) {
- fprintf(sm_ErrorStream, "PreCommit write times: time=%d #pages=%d #writeCalls=%d clientMsgs=%d\n", StatTotalTime_usec/1000, StatPagesWritten, StatWriteCalls, StatClientMsgs);
- StatPagesWritten = StatWriteCalls = StatClientMsgs = StatTotalTime_usec = 0;
- }
-
- /*
- * Temporarily make the transaction active in order to log
- * page deallocations.
- */
- transRec->transState = T_ACTIVE;
-
- initializeList(&(pendingBitmapList));
-
- /* deallocate all temporary files and pages */
- deallocTempFilesPages(transRec);
-
- /*
- * add all the pages in the all the files to be destroyed
- * to the list of pages to deallocate
- */
- if (transDeallocFilePages(transRec) != esmNOERROR) {
- /* clean up dealloc info */
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
-
- /*
- * Log all pending page deallocations
- */
- if (logTransDeallocPages(transRec, &pendingBitmapList) != esmNOERROR) {
- /*
- * For now, just crash, but we should really clean things up
- * and abort the transaction. Clean-up is complicated by
- * the bitmap and volume header pages which are pinned with
- * pending operations.
- */
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
-
- /*
- * Restore transaction to the quiesced state
- */
- transRec->transState = T_QUIESCE;
-
- /*
- * If the transaction generated some log records, make sure they
- * are flushed.
- */
- if (transRec->logRecordCount > 0) {
-
- /*
- * Sync all unix file based volumes which were used by this
- * transaction.
- */
- if (io_SyncTransVolumes(&(transRec->volumeList)) != esmNOERROR) {
- SM_ERROR(TYPE_CRASH, esmINTERNAL);
- }
-
- /*
- * Make sure only one theead is using the global
- * variable DirtyPageLogInfo at a time.
- */
- if (waitSemaphore(&DirtyPageLogInfoSemaphore)) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- /*
- * Fill an array of information for all pages dirtied by
- * this transaction since the last checkpoint.
- */
- numDirtyPages = listDirtyTransPages(transRec, dirtyInfo);
- PRINT_PROGRESS(("logging %d pages as dirty since last checkpoint\n", numDirtyPages));
-
- /*
- * Generate a log record containing the dirty page info
- */
- recordInfo.action = 0;
- recordInfo.type = LOG_REC_TYPE_DIRTYPAGELIST;
- recordInfo.imageCount = 1;
- recordInfo.actionPid = NULL;
- recordInfo.actionLRC = NULL;
- recordInfo.imageSize[0] = numDirtyPages * sizeof(DIRTYPAGELOGINFO);
- recordInfo.imageData[0] = (VOID *) dirtyInfo;
- recordInfo.nextUndoLSN = NULL_LSN;
- recordInfo.flags = REDO_ONLY;
-
- /*
- * write the record to the log
- */
- if ((forceMark = writeNonTransLogRecord(&recordInfo, NULL, NOFLAGS)) < 0) {
-
- /*
- * abort the transaction
- */
- signalSemaphore(&DirtyPageLogInfoSemaphore);
- abortTrans(transRec, Active->errno);
- reply(esmFAILURE, Active->errno, 1, TRUE);
- }
-
- /*
- * Done with DirtyPageLogInfo
- */
- signalSemaphore(&DirtyPageLogInfoSemaphore);
-
- /*
- * we must log the commit record and atomically change the
- * transaction state.
- */
- if (writeTransStateRecord(transRec, LOG_REC_TYPE_COMMIT, ZERO, T_COMMIT, TRUE) < esmNOERROR) {
-
- /*
- * abort the transaction
- */
- abortTrans(transRec, Active->errno);
- reply(esmFAILURE, Active->errno, 1, TRUE);
- }
-
- /*
- * Perform all pending page deallocations
- */
- if (deallocTransPages(transRec, &pendingBitmapList) != esmNOERROR) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- } else if (!transRec->loggingOn) {
- /*
- * Since logging is turned off, we must write all dirty pages
- * since the checkpoint to disk. This is most easily done
- * by calling listDirtyTransPages.
- */
- numDirtyPages = listDirtyTransPages(transRec, dirtyInfo);
- PRINT_PROGRESS(("finished writing %d pages as dirty since last checkpoint\n", numDirtyPages));
-
- } else {
- SM_ASSERT(LEVEL_3, LIST_EMPTY(&(transRec->clientDirtyList)));
- }
-
- SM_ASSERT(LEVEL_3, LIST_EMPTY(&(transRec->fileDeallocList)));
- SM_ASSERT(LEVEL_3, LIST_EMPTY(&(transRec->pageDeallocList)));
- SM_ASSERT(LEVEL_3, LIST_EMPTY(&pendingBitmapList));
-
- /*
- * Make sure all bitmaps are consistent after any
- * deallocation/allocation
- */
- SM_ASSERT(LEVEL_3, io_CheckAllVolumes() == esmNOERROR);
-
- /*
- * check to see if there are any log records
- * that are written for this transaction
- */
- if (transRec->lastLSN != 0) {
-
- /*
- * take the record off the log queue
- */
- removeLogList(transRec);
- }
-
- /*
- * free all the locks
- */
- unlockAll(transRec, esmTRANSCOMMITTED);
-
- /*
- * free the structures
- */
- freeTransVolRecs(transRec);
-
- /*
- * give back the transaction record
- * reset the state to T_INACTIVE
- */
- freeTransRec(transRec);
-
- TotalCommits++;
-
- /*
- * reply with success
- */
- reply(esmNOERROR, esmNOERROR, 1, TRUE);
- }
-